package com.mall.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mall.db.domain.Brief;
import com.mall.db.domain.Stock;
import com.mall.db.service.BriefService;
import com.mall.db.service.ParameterService;
import com.mall.db.service.StockService;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/system/scc")
public class StockController extends BaseController<Stock>{

    @Resource(name = "stockService")
    private StockService ss;

    @Resource(name = "briefService")
    private BriefService bss;

    @Resource(name = "parameterService")
    private ParameterService pc;

    @RequestMapping("/commodity1")
    public void commodity1(){
        QueryWrapper qw=new QueryWrapper();
        bss.remove(qw);

        ss.remove(qw);
        Stock s1=new Stock();
        s1.setCation("标准");
        s1.setPrice("0");
        s1.setNumber(0);
        s1.setState(1);
        ss.save(s1);

        pc.remove(qw);
    }

    @Override
    public Map<String, Object> find(Stock stock) {
        QueryWrapper qw=new QueryWrapper();
        if(!StringUtils.isEmpty(stock.getState())){
            qw.eq("state",stock.getState());
        }
        List<Brief> list= ss.list(qw);
        Map<String,Object> map=new HashMap<>();
        map.put("code",0);
        map.put("data",list);
        return map;
    }

    @Override
    public Map<String, Object> update(Stock stock) {
       boolean b=ss.updateById(stock);
        return this.iud("设置",b,stock);
    }
}
